package client;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;

public class MyClient {
	public static void main(String[] args) throws Exception {
		System.out.println("Client is up.");
		Socket serverToConnect = new Socket(InetAddress.getLocalHost(), 5000);
		System.out.println("Client connected to Server "+ InetAddress.getLocalHost() + " port 5000");
		BufferedReader dataFromServer = new BufferedReader(new InputStreamReader(serverToConnect.getInputStream()));
		PrintWriter dataToServer = new PrintWriter(new OutputStreamWriter(serverToConnect.getOutputStream()));
		
		String myState;
		BufferedReader dataFromKeyboard = new BufferedReader(new InputStreamReader(System.in));
		
		while (!(myState = dataFromKeyboard.readLine()).equals("done")) {
			dataToServer.println(myState);
			dataToServer.flush();
		}
		
		dataFromServer.close();
		dataToServer.close();
		dataFromKeyboard.close();
		serverToConnect.close();
	}
}
